// pages/help/refundRecord/refundRecord.js
let app = getApp()
let request = require('../../../utils/request.js')
let flag = false
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    screenHeight: app.globalData.screenHeight,
    refunList: [],
    pageNum: 1,
    pageSize: 10,
    isCanNext: true,
    verifyLoginDialog: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let token = wx.getStorageSync('token');
    if (token) {
      this.getRefunList()
    } else {
      this.setData({
        verifyLoginDialog: true
      })
    }
  },
  verifyLogin() {
    this.getRefunList()
  },
  getRefunList(next) {
    let that = this
    let url = '/order/order-refund/getOrderRefundPage'
    let parmas = {
      pageNum: that.data.pageNum,
      pageSize: that.data.pageSize
    }
    request.http(url, 'GET', parmas)
      .then(res => {
        let data = res.data
        if (data.code == 200) {
          let refunLists = that.data.refunList
          let refunList = data.data.records
          if (next) {
            refunList = refunLists.concat(data.data.records)
            if (data.data.records.length <= 0) {
              that.setData({
                isCanNext: false
              })
            }
          }
          that.setData({
            refunList: refunList
          })
          flag = false
        }
      })
  },
  /**
   * 滚动条滚动到底部触发
   */
  scrollLower: function () {
    if (flag) {
      return
    }
    flag = true
    this.setData({
      pageNum: this.data.pageNum + 1
    })
    this.getRefunList(true)
  },
})